package com.bestvike.portal.config;

import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.context.request.WebRequest;

import java.util.Map;

@Component
public class CustomErrorAttribute extends DefaultErrorAttributes {
    @Override
    public Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) {
        Map<String, Object> result = super.getErrorAttributes(webRequest, includeStackTrace);
        // result.put("status", 500);
        String message = (String) result.get("message");
        if (!StringUtils.isEmpty(message)) {
            // Read timed out
            if (message.equalsIgnoreCase("Read timed out")) {
                result.put("message", "接口请求超时");
            }
        }
        return result;
    }
}
